/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.factory.server.consumers;

import com.factory.server.json.Plan;
import com.factory.server.scheduler.SchedulerServiceIface;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

/**
 *Takes tasks from tasks queue and performs computation.
 * @author milos
 */
@Component
@Scope("prototype")
public class Consumer implements Runnable {

    static final Logger LOG = Logger.getLogger(Consumer.class.getName());
    private TasksQueue tasksQueue;

    public Consumer() {
    }

    public TasksQueue getTasksQueue() {
        return tasksQueue;
    }

    public void setTasksQueue(TasksQueue tasksQueue) {
        this.tasksQueue = tasksQueue;
    }
    @Autowired
    private SchedulerServiceIface schedulerService;

    public void run() {

        while (true) { //TODO dorobit vypinaci signal
            Plan plan = schedulerService.getTasksQueue().get();
            if (plan != null) {
                schedulerService.performPlanTask(plan);
              
                schedulerService.getSchedulerTaskQueue().get();
            }
        }

    }
}
